import { useEffect } from "react";
import { Project } from "types/Project";
import { useHttp } from "./http";
import { cleanObject } from "utils/index";
import { useAsync } from "./use-async";
export const useProjects = (param?: Partial<Project>) => {
  const { run, ...result } = useAsync<Project[]>();
  const client = useHttp();
  const fetchProject = () => client(`projects`, { data: cleanObject(param || {}) })
  useEffect(() => {
    // 使用useAsync优 化异步操作
    // run里面传入一个返回promise的函数
    // 没有传入param的时候传入一个空对象
    run(fetchProject(), {retry: fetchProject});
    // eslint-disable-next-line
  }, [param]);
  return result;
};
